<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>租赁修改</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap-datetimepicker.min.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/rent/rentInfo.css">
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
    <style>
        .btn{
            width:100px;
            line-height:15px;
            background:#35acfd;
            color:white;
        }
    </style>
    <script>
        $(document).ready(function () {
            <shiro:hasPermission name="super:role">
                initHosp("hospId");
            </shiro:hasPermission>
            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    rentMan: {
                        validators: {
                            notEmpty: true,
                            regexp: {//正则验证
                                regexp: /^[0-9]+$/,
                                message: '请输入正确的手机号'
                            },
                        }
                    },
                    rentTel: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    rentTime: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    rentMoney: {
                        validators: {
                            numeric: true
                        }
                    },
                    backTime: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    backStatus: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    expectBackTime: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    idCard: {
                        validators: {
                            regexp: {//正则验证
                                regexp:/(^\d{15}$)|(^\d{17}([0-9]|X)$)/,
                                message: '所输入的内容不符合要求'
                            }
                        },

                    }
                    <shiro:hasPermission name="super:role">
                    ,
                    hospId: {
                        validators: {
                            notEmpty: true
                        }
                    }
            	    </shiro:hasPermission>
                    
                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();
                $.ajax({
                    url: '${URL_RENT_UPDATEHISTORY}',
                    type: 'post',
                    data: $('#myForm').serialize(),
                    async: false, //默认为true 异步
                    dataType: 'json',
                    error: function () {
                        alert('error');
                    },
                    success: function (data) {
//                        console.log(data);
                        if(!data.success){
                            alert("更新失败，失败原因：" + data.msg);
                        }
                        closeFrame();
                    }
                });
            });


            initLayDate("#rentTime", "#rentTime");
            <c:if test="${entity.rentStatus != 0}">
            	initLayDate("#backTime", "#backTime");
            </c:if>
            initLayDate("#expectBackTime", "#expectBackTime");
            //initInstr("#instrumentId");
        });

        //关闭并刷新
        function closeFrame() {
            window.parent.closeModal();
        }
        function initDateTime(id, timeId) {
            var t = $(id).datetimepicker({
                language: 'zh-CN',
                weekStart: 0,
                todayBtn: true,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            }).on('hide', function (e) {
                $('#myForm').bootstrapValidator('revalidateField', $(timeId));
            });
        }
        function initLayDate(id){
            laydate({
                elem: id,
                istime: true,
                format: 'YYYY-MM-DD',
                choose:function(dates){ //选择好日期的回调
                    $('#myForm').bootstrapValidator('revalidateField', $('#backTime'));
                }
            })
        }

        function formatRepo(repo) {
            if (repo.loading) return repo.text;
            var markup = "<div class='select2-result-repository clearfix'>" +
                "<div class='select2-result-repository__title'>" + repo.hospName + "</div></div>";
            return markup;
        }

        function formatRepoSelection(repo) {
            return repo.hospName;
        }

        function initHosp(id){
            $("#"+id).select2({
                placeholder: '请选医院',
                ajax: {
                    url: '${URL_HL_HOSPITAL_SELECT}',
                    dataType: 'json',
                    type: "post",
                    delay: 250,
                    data: function (params) {
                        var data=new Object();
                        data["iDisplayLength"]=10;
                        if(params.page==undefined){
                            data["iDisplayStart"]=0;
                        }else {
                            data["iDisplayStart"]= (params.page-1)*10;
                        }
                        if(params.term!=undefined){
                            data["hospName"]= params.term;
                        }
                        return data;
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.data,
                            pagination: {
                                more: (params.page * 10) < data.msg
                            }
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                minimumInputLength: 0,
                templateResult: formatRepo, // omitted for brevity, see the source of this page
                templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
            });
        }

    </script>
</head>
<body style="width: 98%">
<div class="header">
    <h1>租借历史修改</h1>
</div>
<form id="myForm" class="form-horizontal" method="post">
    <div class="clearfix">
        <input type="hidden" id="rentStatus" name="rentStatus" value="${entity.rentStatus}">
        <div class="form-group">
            <label class="control-label">租借编号</label>
            <input type="text" id="rentId" name="rentId" class="form-control" value="${entity.rentId}"
                       readonly="readonly">
        </div>
        <div class="form-group">
            <label class="control-label">设备名称</label>
            <input type="text" id="instrumentType" name="instrumentType" class="form-control" value="${entity.instrumentType}"
                       readonly="readonly">
        </div>
        <div class="form-group">
            <label class="control-label">租借人</label>
            <input type="text" id="rentMan" name="rentTel" class="form-control" value="${entity.rentMan}">
        </div>
        <div class="form-group">
            <label class="control-label">租借人电话</label>
            <input type="text" id="rentTel" name="rentMan" class="form-control" value="${entity.rentTel}">
        </div>
        <div class="form-group">
            <label class="control-label">租借人身份证号</label>
            <input type="text" id="idCard" name="idCard" class="form-control" style="padding-right: 30px;" value="${entity.idCard}">
        </div>
        <div class="form-group">
            <label class="control-label">租借日期</label>
            <div id="TimeArea" class="input-group date form_date">
                <input type="text" id="rentTime" name="rentTime" value="${entity.rentTime}" class="form-control" placeholder="选择日期" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">已付押金</label>
            <input type="text" id="rentMoney" name="rentMoney" class="form-control" value="${entity.rentMoney}">
        </div>
        <div class="form-group">
            <label class="control-label">预归还日期</label>
            <div class="input-group date form_date">
                <input type="text" id="expectBackTime" name="expectBackTime" value="<fmt:formatDate value="${entity.expectBackTime}"  type="date" pattern="yyyy-MM-dd"/>" class="form-control" placeholder="选择日期" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">租借备注</label>
            <input type="text" id="rentComment" name="rentComment" class="form-control"
                       value="${entity.rentComment}">
        </div>
        <c:if test="${entity.rentStatus != 0}">
        <div class="form-group">
            <label class="control-label">归还日期</label>
            <div id="TimeArea2" class="input-group date form_date">
                <input type="text" id="backTime" name="backTime" value="${entity.backTime}" class="form-control" placeholder="选择日期"  readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">返还押金</label>
            <input type="text" id="backMoney" name="backMoney" class="form-control" value="${entity.backMoney}">
        </div>
        <div class="form-group">
            <label class="control-label">设备状态</label>
            <select id="backStatus" name="backStatus" class="form-control" <c:if test="${entity.rentId != lastRent.rentId}"></c:if>>
                <medi:configOpt name="backStatus" key="${entity.backStatus}"/>
            </select>
        </div>
        <div class="form-group">
            <label class="control-label">归还备注</label>
            <input type="text" id="backComment" name="backComment" class="form-control" value="${entity.backComment}">
        </div>
		</c:if>
        <%--所属医院--%>
        <shiro:hasPermission name="super:role">
	        <div class="form-group">
                <label class="control-label">所属医院</label>
                <select id="hospId" name="hospId"  class="form-control">
                    <c:if test="${hospital!=null}">
                        <option value="${hospital.id}">${hospital.hospName}</option>
                    </c:if>
                </select>
	        </div>
	    </shiro:hasPermission>
	    <shiro:lacksPermission name="super:role">
       		<input type="hidden" id="hospId" name="hospId" class="form-control" value="${hospital.id}">
		</shiro:lacksPermission>
    </div>
    </div>
    <div class="form-group submitBtn">
        <button type="button" class="btn" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">关闭</button>
        <button type="submit" name="submit" class="btn">保存</button>
    </div>
</form>
</body>
</html>